<!-- 用户福分 -->
<template>
  <page-header-wrapper>
    <a-card class="table-card">
      <GzSearchForm :searchFunc="searchFunc" :resetFunc="()=>{searchData = {}}" searchConditionNum="6">
        <GzTextUp v-model:value="searchData['phone']" placeholder="用户手机号" />
        <GzTextUp v-model:value="searchData['fansId']" placeholder="fansId" />
      </GzSearchForm>

      <!-- 列表渲染 -->
      <GzTable
        ref="infoTableRef"
        :init-data="true"
        :req-table-data-func="reqTableDataFunc"
        :table-columns="tableColumns"
        :search-data="searchData"
      >
        <template #bodyCell="{ column, record }">
          <template v-if="column.key === 'infoType'">
            <template v-if="record.infoType === 'ACTIVITY'">活动</template>
            <template v-if="record.infoType === 'COUPON'">卡券</template>
            <template v-if="record.infoType === 'GOODS'">实物奖品</template>
            <template v-if="record.infoType === 'VIRTUAL'">虚拟券</template>
          </template>

          <template v-if="column.key === 'operation'">
            <a-button v-if="$access('ENT_FANS_SCORE_RECORD_INFO_VIEW')" type="link" @click="() => ScoreRecordModalRef.show(record.userId)">福分记录</a-button>
          </template>
        </template>
      </GzTable>
    </a-card>
  </page-header-wrapper>

  <!-- 福分记录弹窗 -->
  <ScoreRecordModal ref="ScoreRecordModalRef" />
</template>

<script lang="ts" setup>
import { req, API_URL_FANS_SCORE_LIST } from '@/api/manage'
import { ref, reactive, getCurrentInstance } from 'vue'
import ScoreRecordModal from './ScoreRecordModal.vue'

const { $access } = getCurrentInstance()!.appContext.config.globalProperties

const infoTableRef = ref()
const ScoreRecordModalRef = ref()
let tableColumns = reactive([
  // { key: 'fansId', title: 'fansID',dataIndex: 'fansId',fixed: 'left' },
  { key: 'fansId', title: 'fansId',dataIndex: 'fansId' },
  { key: 'phone', title: '用户手机号',dataIndex: 'phone' },
  // { key: 'scoreNum', title: '变动福分',dataIndex: 'scoreNum',},
  // { key: 'reason', title: '变动原因',dataIndex: 'reason' },
  { key: 'currentScore', title: '当前剩余总福分',dataIndex: 'currentScore' },
  { key: 'operation', title: '操作',dataIndex: 'operation' }
])

const searchData:any = ref({})

// 请求table接口数据
function reqTableDataFunc(params: any) {
  const fansId = history.state.fansId
  if (fansId) {
    searchData.value.fansId = fansId
    history.state.fansId = null
    return req.add(API_URL_FANS_SCORE_LIST, { ...params, fansId })
  }
  return req.add(API_URL_FANS_SCORE_LIST, params)
}

function searchFunc() {
  infoTableRef.value.refTable(true)
}

</script>
